﻿@{
    ViewBag.Title = "Country Site Configuration";
}
<br/>
<h2>Country Site Configuration</h2>
<br/>

@(Html.Telerik().Grid<Century.Models.Common.CountrySite>()
    .Name("Grid")

    .DataKeys(keys => keys.Add(c => c.Id))
    .Columns(columns =>
    {
        columns.Bound(o => o.Id).Hidden().ReadOnly(true);
        columns.ForeignKey(o => o.CountryId, (System.Collections.IEnumerable)ViewBag.CountryList, "Id", "Name").Width(200).Title("Country");
        columns.ForeignKey(o => o.LanguageId, (System.Collections.IEnumerable)ViewBag.LanguageList, "Id", "Name").Width(150).Title("Language");
        columns.Bound(o => o.Name).Title("Local Name");
        columns.Bound(o => o.Path).Title("SitePath");
        columns.Bound(o => o.IsDefault);
        columns.Bound(o => o.IsActive);
        columns.Bound(o => o.SiteAnalyticsScript).Hidden();
        columns.Bound(o => o.LiveApplicationUrl).Hidden();
        columns.Bound(o => o.DemoApplicationUrl).Hidden();
        columns.Bound(o => o.LoginUrl);
        columns.Bound(o => o.SiteAddress);

        columns.Command(command =>
        {
            command.Edit().ButtonType(GridButtonType.Image).HtmlAttributes(new { style = "border: 0px;" } );
        }).Width(50);
        
        columns.Command(command =>
        {
            command.Custom("GenerateLabels")
            .ButtonType(GridButtonType.Image)
            // Specify which fields from the bound data item to include in the route (pass as action method arguments)
            .DataRouteValues(route => route.Add(o => o.Id).RouteKey("Id"))
            // Name of the custom command (used to differentiate between multiple custom commands)
            // Make ajax requests
            .Ajax(true)
            .HtmlAttributes(new { @class = "t-generatelabel" })
            // Which action method to call
            .Action("GenerateLabels", "SiteConfiguration");
        }).Width(50);
        
    })
        .ClientEvents(clientEvents =>
        {
            clientEvents.OnEdit("editClick");
        })
                 .DataBinding(dataBinding => dataBinding.Ajax().Select("GetCountrySiteList", "SiteConfiguration").Update("EditCountrySite", "SiteConfiguration"))
        .Groupable()
        .Filterable()
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .Sortable()
        .Resizable(config =>
                {
                    config.Columns(true);
                })
            .Reorderable(config =>
            {
                config.Columns(true);
            })
            .ColumnContextMenu()
    )
<script type="text/javascript">

    function editClick(e) {
        $(e.form).closest(".t-window-content").width(750).height(750);
        var popup = $("#" + e.currentTarget.id + "PopUp");
        popup.css({ "left": ($(window).width() / 2 - $(popup).width() / 2) + "px", "top": ($(window).height() / 2 - $(popup).height() / 2) + "px" });
        $('.editor-label:eq(11)').hide();
        $('.editor-field:eq(11)').hide();
    }
    function OnLoad(e) {
        // your code
    }
</script>
<style type="text/css">
    .editor-field .text-box
    {
        width: 590px;
    }
</style>
